<?php

namespace Admin\Model;

/**
 * Created by PhpStorm.
 * User: Ysll <754060604@qq.com>
 * Date: 2017/10/7
 * Time: 16:18
 */
class ProductCategories extends Model
{
    protected $tableName = 'product_categories';

    /**
     * 返回所有分类
     *
     * @return array|bool|null
     */
    public static function all()
    {
        return self::getInstance()->select();
    }

    /**
     * 创建
     *
     * @param array $data
     * @return int|null|false
     */
    public static function creates(array $data)
    {
        return self::getInstance()->add($data);
    }

    /**
     * 更新数据
     *
     * @param int $id
     * @param array $data
     * @return bool
     */
    public static function update($id, array $data)
    {
        $data['updated_at'] = date('Y-m-d H:i:m');
        return self::getInstance()->where('id = ' . $id)->save($data);
    }

    /**
     * 删除数据
     *
     * @param $id
     * @return mixed
     */
    public static function destroy($id)
    {
        return self::getInstance()->where('id = ' . $id)->delete();
    }

    public static function findById($id)
    {
        return self::getInstance()->where('id = ' . $id)->find();
    }
}